/*
 * MotorsTest.java
 *
 * Created on 7. zari 2007, 13:24
 */
package robotour.hardware.oldmotors;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import robotour.hardware.oldmotors.MotorsPanel;

/**
 *
 * @author  PC
 */
class MotorsTest extends javax.swing.JFrame {

    private Motors motors;

    /** Creates new form MotorsTest */
    public MotorsTest(Motors motors) {
        this.motors = motors;
        initComponents();
        add(new MotorsPanel(motors), BorderLayout.NORTH);
//        add(Device.ssc32.getSmallDevPanel(), BorderLayout.EAST);
        pack();
    }
    int lefts = 0, rights = 0;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        leftTF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("MotorsTest");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        leftTF.setText("11111111");
        leftTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                leftTFActionPerformed(evt);
            }
        });

        jLabel1.setText("jLabel1");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("jLabel2");

        jButton1.setText("click here first");
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton1KeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(leftTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2))
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING))))
                .addContainerGap(121, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(leftTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(115, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
        System.out.println("" + KeyEvent.getKeyText(evt.getKeyCode()));
        switch (evt.getKeyCode()) {
            case KeyEvent.VK_UP:
                rights++;
                lefts++;
                break;
            case KeyEvent.VK_DOWN:
                rights--;
                lefts--;
                break;
            case KeyEvent.VK_LEFT:
                lefts--;
                rights++;
                break;
            case KeyEvent.VK_RIGHT:
                lefts++;
                rights--;
                break;
            case KeyEvent.VK_W:
                lefts++;
                break;
            case KeyEvent.VK_S:
                lefts--;
                break;
            case KeyEvent.VK_SPACE:
                lefts = 0;
                rights = 0;
                break;

            case KeyEvent.VK_SHIFT:
                motors.turbo();
                lefts = 0;
                rights = 0;
                break;
        }
        jLabel1.setText("" + lefts);
        jLabel2.setText("" + rights);
        motors.setSpeeds(lefts, rights);
    }//GEN-LAST:event_jButton1KeyPressed

    private void leftTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_leftTFActionPerformed
//        DeviceManager.getSsc32().setBank(1, Integer.parseInt(leftTF.getText(), 2));
    }//GEN-LAST:event_leftTFActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
//                MotorsTest mt = new MotorsTest(new Motors());
//                mt.setVisible(true);
////                while (true) {
////                    mt.repaint();
////                    try {
////                        Thread.sleep(100);
////                    } catch (InterruptedException ex) {
////                        ex.printStackTrace();
////                    }
////                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField leftTF;
    // End of variables declaration//GEN-END:variables
}
